﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DDF.Data.Providers;
using System.Data;
using System.Data.SqlClient;
using ARR.Entities.Gateways;
using DDF.Data;

namespace ARR.DataModel.Repositories
{
    public static partial class TempHistoryDetailsRepository
    {
        public static void TruncateTable()
        {
            using (SqlDataProvider database = new SqlDataProvider(connString, "{0}Cursor", "dbo"))
            {
                database.NewCommand("TRUNCATE TABLE TempHistoryDetails ", System.Data.CommandType.Text);
                database.ExecuteNonQuery();
            }
        }

        public static void UpdateCategoryIds()
        {
            using (SqlDataProvider database = new SqlDataProvider(connString, "{0}Cursor", "dbo"))
            {
                database.NewCommand("TempHistoryDetails_UpdateCategoryIds", CommandType.StoredProcedure);
                database.ExecuteNonQuery();
            }
        }

        public static void BulkCopy(DataTable detailsToCopy)
        {
            using (SqlConnection conn = new SqlConnection(connString))
            {
                conn.Open();
                using (SqlBulkCopy bulk = new SqlBulkCopy(conn))
                {
                    bulk.DestinationTableName = "TempHistoryDetails";
                    bulk.BulkCopyTimeout = 300;
                    bulk.WriteToServer(detailsToCopy);
                    bulk.Close();
                }

                conn.Close();
            }
        }
    }
}
